package com.letter.otools.day.user;

import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;

import android.view.MenuItem;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;

import com.letter.otools.day.BaseActivity;
import com.letter.otools.day.Constants;
import com.letter.otools.day.R;
import com.letter.otools.day.util.AppUtils;
import com.letter.otools.day.util.WebViewUtils;
import com.letter.otools.day.view.KeyValueView;


public class AboutUsActivity extends BaseActivity implements View.OnClickListener {

    private KeyValueView version;
    private KeyValueView contactUs;
    private ActionBar actionBar;
    KeyValueView deal;

    @Override
    protected int getLayout() {
        return R.layout.activity_user_about_us;
    }

    void initToolBar() {
        Toolbar toolbar = findViewById(R.id.Toolbar);
        setSupportActionBar(toolbar);

        actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeAsUpIndicator(AppUtils.getNightMode(this) == MODE_NIGHT_YES ? R.drawable.ic_toolbar_back_white_24dp : R.drawable.ic_toolbar_back_gray_24dp);
            actionBar.setTitle("About");
        }
    }

    @Override
    protected void initView() {
        initToolBar();
        version.setValue(AppUtils.getAppVersionName(this, getPackageName()));
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void initBinder() {
        version = findViewById(R.id.version);
        contactUs = findViewById(R.id.contactUs);
        contactUs.setOnClickListener(this);
        deal = findViewById(R.id.deal);
        deal.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.contactUs) {
            AppUtils.copy2ClipboardManager(this, contactUs.getValueText());
        }if (view.getId() == R.id.deal) {
            WebViewUtils.goWeb(this, "Privacy Policy", Constants.privacyUrl);
        }
    }
}
